package com.edu.commons;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;

/**
 * @ProjectName: summer-project
 * @Titile: MD5Utils
 * @Author: Lucky
 * @Description: MD5加密工具
 */
public class MD5Utils {

    /**
     * 加密方法
     * @param password 密码明文
     * @param salt 盐值
     * @param times hash次数
     * @return 密文
     */
    public static String encrypt(String password,String salt,int times){
        //重组密码
        password = password + salt + password ;
        //循环散列
        for (int i = 0; i < times; i++) {
           password = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8));
        }
        return password;
    }
}
